package com.avit.tv.kui.pro.utils;

import com.avit.tv.kui.utils.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * 组织key code
 *
 * @author like
 * @date 2020/8/29
 */
public class KeyCodeChecks {

    private final List<Integer> codes;

    private KeyCodeChecks (List<Integer> codes){
        this.codes = codes;
    }

    public boolean checkKeycode (int pressKeycode ){
         if (codes == null||codes.isEmpty()) {
             Log.w(this,"codes is not inited , please use CodesBuilder for init");
             return false;
         }
         for (int code : codes){
             if (pressKeycode == code) {
                 return true;
             }
         }
         return false;
    }


    public static final class CodesBuilder {
        private List<Integer> codes = new ArrayList<>();
        public CodesBuilder initKeyCode(int ... keycodes) {
            codes.clear();
            for (int code : keycodes) {
                codes.add(code);
            }
            return this;
        }

        public KeyCodeChecks build(){
            return new KeyCodeChecks(codes);
        }

    }
}
